/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.bff.designtime.generator.api.actioninterface.method;

import com.inspur.edp.bef.component.ICompParameter;
import com.inspur.edp.bef.component.ICompParameterCollection;
import com.inspur.edp.bef.component.base.CompMethod;
import com.inspur.edp.bff.designtime.generator.api.VmApiGenContext;
import com.inspur.edp.caf.generator.baseInfo.InterfaceMethodGenerateInfo;
import com.inspur.edp.caf.generator.baseInfo.ParameterInfo;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.InterfaceMethodGenerator;
import com.inspur.edp.caf.generator.method.InterfaceMethodGeneratorContext;
import com.inspur.edp.cef.generator.overall.GenUtils;
import com.inspur.edp.cef.generator.overall.Utils;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public class ActionInterfaceMethodGenerator extends InterfaceMethodGenerator {

  private CompMethod method;
  private ICompParameterCollection parameterCollection;
  private String methodName;
  private VmApiGenContext apiGenCtx;

  public ActionInterfaceMethodGenerator(CompMethod method, String methodName,
      ICompParameterCollection parameterCollection, VmApiGenContext apiGenCtx) {
    this.method = method;
    this.methodName = methodName;
    this.parameterCollection = parameterCollection;
    this.apiGenCtx = apiGenCtx;
  }

  @Override
  protected InterfaceMethodGeneratorContext createClassInfoContext() {
    return new InterfaceMethodGeneratorContext();
  }

  @Override
  protected InterfaceMethodGenerateInfo createClassMethodInfo() {
    return new InterfaceMethodGenerateInfo();
  }

  @Override
  protected java.util.ArrayList<ModifierKeyword> getAccessModifiers() {
    return new java.util.ArrayList<ModifierKeyword>();
  }

  @Override
  protected String getMethodName() {
    return methodName;
  }

  @Override
  protected ArrayList<ParameterInfo> getParameterCollection() {
    java.util.ArrayList<ParameterInfo> result = new java.util.ArrayList<ParameterInfo>();
    if (parameterCollection != null) {
      for (Object item : parameterCollection) {
        ICompParameter par = (ICompParameter) item;
        ParameterInfo tempVar = new ParameterInfo();
        tempVar.setParamName(par.getParamCode());
        tempVar.setParamType(Utils.getNativeType(par, apiGenCtx));
        result.add(tempVar);
      }
    }
    return result;
  }

  @Override
  protected TypeInfo getReturnType() {
    return Utils.getReturnType(method, apiGenCtx.getVmGenContext());
  }
}
